import 'package:base_plugin/base_plugin.dart';
import 'package:finance_app/generated/a.dart';
import 'package:finance_app/src/common/app_colors.dart';
import 'package:flutter/material.dart';

class BasePage extends DefaultPageManager {
  @override
  Widget buildEmptyWidget(BuildContext context,
      {VoidCallback onTry, String tip}) {
    Widget child = Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        Image.asset(
          A.assetsImagesStyleEmpty_inbox_Monochromatic_1,
          width: getDp(98),
          height: getDp(74),
        ),
        SizedBox(
          height: getDp(20),
        ),
        Text(
          tip,
          style: TextStyle(
            color: aceGrayColor,
            fontSize: getSp(16),
            fontWeight: FontWeight.w400,
            height: 1,
          ),
        )
      ],
    );

    child = Padding(
        padding: EdgeInsets.only(
          top: getDp(35),
        ),
        child: child);
    return LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
      final biggest = constraints.biggest;
      if (biggest.height == double.infinity) {
        return child;
      } else {
        return Center(
          child: child,
        );
      }
    });
  }

  @override
  Widget buildErrorWidget(
    BuildContext context, {
    String message,
    VoidCallback onTry,
  }) {
    Widget child = Column(
      mainAxisSize: MainAxisSize.min,
      children: [
        SizedBox(
          height: getDp(40),
        ),
        Image.asset(
          A.assetsImagesStyleEmpty_inbox_Monochromatic_1,
          width: getDp(98),
          height: getDp(74),
        ),
        SizedBox(
          height: getDp(20),
        ),
        PressedOpacityButton(
          onPressed: onTry,
          child: Text(
            message ?? 'try again',
            style: TextStyle(
              color: aceGrayColor,
              fontSize: getSp(16),
              fontWeight: FontWeight.w400,
              height: 1,
            ),
          ),
        ),
      ],
    );
    return LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
      final biggest = constraints.biggest;
      if (biggest.height == double.infinity) {
        return Padding(
            padding: EdgeInsets.only(
              top: getDp(35),
            ),
            child: child);
      } else {
        return Center(
          child: child,
        );
      }
    });
  }

  @override
  Widget buildLoadingWidget(
    BuildContext context,
  ) {
    Widget child = Padding(
        padding: EdgeInsets.only(
          top: getDp(35),
        ),
        child: Center(
          child: CircularProgressIndicator(),
        ));
    return LayoutBuilder(
        builder: (BuildContext context, BoxConstraints constraints) {
      final biggest = constraints.biggest;
      if (biggest.height == double.infinity) {
        return child;
      } else {
        return Center(
          child: child,
        );
      }
    });
  }

  @override
  Widget buildNotFoundWidget(String path) {
    return Center(
      child: Text(
        'not found path:$path',
        style: TextStyle(
          color: Colors.red,
        ),
      ),
    );
  }

  @override
  Widget buildExceptionWidget(FlutterErrorDetails flutterErrorDetails) {
    return Center(
      child: Text(
        '抱歉!程序出了点问题\n${flutterErrorDetails.exceptionAsString()}',
        textAlign: TextAlign.center,
      ),
    );
  }
}
